<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="订单号:" prop="order_id.value">
                            <el-input v-model="queryParams.order_id.value" placeholder="请输入订单号" clearable />
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item label="内容详情:" prop="cancel_reason_text.value">
                            <el-input type="textarea" :rows="4" v-model="queryParams.cancel_reason_text.value" placeholder="请输入内容详情" clearable />
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <p>
                <span style="color:#fd2f2f;">{{orderrefund_msg}}</span>
            </p>
            
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col> -->
                <!-- <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col> -->
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleprocessed" v-hasPermi="api.processed">修改为已处理</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-plus" size="mini" @click="handleunprocessed" v-hasPermi="api.unprocessed">修改为未处理</el-button>
                </el-col>
                <!-- <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col> -->
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
                <el-tab-pane v-for="(item, index) in cancels" :key="index" :label="item.label" :name="item.value.toString()">
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <!-- <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope"> -->
                            <!-- <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="info" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->
                        <!-- </template>
                    </el-table-column>
                </template> -->
            </qa-table>
            </el-tab-pane>
            </el-tabs>

            <el-dialog :title="title1" :visible.sync="dialogTableVisible">
                <el-table :data="msgdata">
                    <el-table-column property="msg" label="日志" width=""></el-table-column>
                </el-table>
            </el-dialog>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            dialogTableVisible: false,
            title1: '请等待',
            // table结构
            columns: [
                {
                    visible: true,
                    label: '订单号',
                    prop: 'order_id',
                },
                {
                    visible: true,
                    label: 'SKU详情',
                    prop: 'skus_info',
                },
                {
                    visible: true,
                    label: '取消状态',
                    prop: 'cancel_status',
                },
                {
                    visible: true,
                    label: '取消原因',
                    prop: 'cancel_reason',
                }, {
                    visible: true,
                    label: '取消原因详情',
                    prop: 'cancel_reason_text',
                },
                {
                    visible: true,
                    label: '取消类型',
                    prop: 'cancel_type',
                },
                {
                    visible: true,
                    label: '角色',
                    prop: 'role',
                },
                {
                    visible: true,
                    label: '处理时间',
                    prop: 'createtime',
                },
            ],
            // 接口地址
            api: {
                index: `/admin/orderrefund/index`,
                find: `/admin/orderrefund/find`,
                add: `/admin/orderrefund/add`,
                edit: `/admin/orderrefund/edit`,
                delete: `/admin/orderrefund/delete`,
                export: `/admin/orderrefund/export`,
                unprocessed: `/admin/orderrefund/unprocessed`,
                processed: `/admin/orderrefund/processed`,
                status: `/admin/orderrefund/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                order_id: { value:undefined, op: '%like%'},
                cancel_status: { value:[], op: '='},
                cancel_reason_text: { value:undefined, op: '%like%'},

            },
            cancels: [
                { label: '全部', value: '' },
                { label: '取消退款请求', value: 'CANCELLATION_REQUEST_CANCEL' },
                { label: '已退款', value: 'CANCELLATION_REQUEST_COMPLETE' },
                { label: '正在处理', value: 'CANCELLATION_REQUEST_PENDING' },
            ],
            activeTab: '',
            msgdata:[],

        }
    },
    created () {
        this.initIndex()
    },
    watch: {
        
    },
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
          //订单状态切换
        handleStatus(tab) {
            this.queryParams.cancel_status.value = tab.name
            this.submitSearch()
        },

        handleprocessed(row) {
            if(this.ids == ''){
                return this.msgError('请勾选再操作')
            }
            this.$confirm(`是否确认修改为已处理?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    this.processeds()
                })
                .catch(() => {})
        },

        async processeds() {
            await this.request.get(this.api.processed, { params: { id:this.ids } })
            this.initIndex()
            this.msgSuccess('操作成功')
        },
        
        handleunprocessed(row) {
            if(this.ids == ''){
                return this.msgError('请勾选再操作')
            }
            this.$confirm(`是否确认修改为未处理?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    this.unprocesseds()
                })
                .catch(() => {})
        },

        async unprocesseds() {
            await this.request.get(this.api.unprocessed, { params: { id:this.ids } })
            this.initIndex()
            this.msgSuccess('操作成功')
        },

    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
